#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll rr() {
    ll s = 0, w = false, c = getchar();
    for (; !isdigit(c); c = getchar())
        w = w || c == '-';
    for (; isdigit(c); c = getchar())
        s = s * 10 + c - '0';
    return w ? -s : s;
}

// END OF HEADER

int main() {
    priority_queue<int, vector<int>, greater<int>> pq;

    int n = rr();
    for (int i = 0; i < n; i++) {
        pq.push(rr());
    }
    int sum = 0;
    while (pq.size() >= 2) {
        int x = pq.top();
        pq.pop();
        int y = pq.top();
        pq.pop();
        sum += x + y;
        pq.push(x + y);
    }
    printf("%d", sum);

    return 0;
}
